package com.onadake.web.controller;

import org.apache.commons.lang3.builder.ToStringBuilder;

import com.onadake.utils.Dates;
import com.onadake.utils.ValidationUtils;
import com.onadake.web.domain.UserProfile;

/**
 * Form model for registration data.
 * 
 * @author radek.hecl
 *
 */
public class RegistrationModel {

    /**
     * Email which is used as log on name.
     */
    private String email;

    /**
     * Password to the account.
     */
    private String password;

    /**
     * Kanji name of the user.
     */
    private String kanjiName;

    /**
     * Kana name of the user.
     */
    private String kanaName;

    /**
     * Date of birth.
     */
    private String birthDate;

    /**
     * Status of accept terms box.
     */
    private String acceptTerms;

    /**
     * String which is used for human verification.
     */
    private String humanCheck;

    /**
     * Creates new instance.
     */
    public RegistrationModel() {
    }

    /**
     * Sets email which is used as log on name.
     * 
     * @param email email
     */
    public void setEmail(String email) {
        this.email = email;
    }

    /**
     * Returns password for the account.
     * 
     * @return password
     */
    public String getPassword() {
        return password;
    }
    
    /**
     * Sets password for the account.
     * 
     * @param password password
     */
    public void setPassword(String password) {
        this.password = password;
    }

    /**
     * Sets kanji name of user.
     * 
     * @param kanjiName kanji name
     */
    public void setKanjiName(String kanjiName) {
        this.kanjiName = kanjiName;
    }

    /**
     * Sets kana name of user.
     * 
     * @param kanaName kana name
     */
    public void setKanaName(String kanaName) {
        this.kanaName = kanaName;
    }

    /**
     * Sets birth date. Format is yyyy/MM/dd.
     * 
     * @param birthDate birth date in yyyy/MM/dd format
     */
    public void setBirthDate(String birthDate) {
        this.birthDate = birthDate;
    }

    /**
     * Sets whether terms are accepted or not.
     * 
     * @param acceptTerms whether terms are accepted or not
     */
    public void setAcceptTerms(String acceptTerms) {
        this.acceptTerms = acceptTerms;
    }

    /**
     * Returns string which is used for human verification.
     * 
     * @return string which is used for human verification
     */
    public String getHumanCheck() {
        return humanCheck;
    }
    
    /**
     * Sets string which used for human verification.
     * 
     * @param humanCheck string which is used for human verification
     */
    public void setHumanCheck(String humanCheck) {
        this.humanCheck = humanCheck;
    }
    
    /**
     * Returns the user profile.
     * 
     * @return user profile
     */
    public UserProfile getUserProfile() {
        ValidationUtils.guardEquals(true, Boolean.valueOf(acceptTerms), "acceptTerms must be true");
        return new UserProfile.Builder().
                setEmail(email).
                setKanjiName(kanjiName).
                setKanaName(kanaName).
                setBirthDate(Dates.getDateFromString(birthDate, "yyyy/MM/dd")).
                build();
    }
    
    @Override
    public String toString() {
        return ToStringBuilder.reflectionToString(this);
    }
}
